<?
class search
{
	static public function cats($db,$c1id,$c2id,$c3id,$c4id,
						$page,$rows,
						$good,
						$q,
						$order,
						$gLocation)
	{
	   $where = array(
       		"where" =>" where `upload` = 1 ",
       );
       if($c1id)
       {
            $where['where']  .= " and c1id = :c1id ";
	   		$where['bind']['c1id']= $c1id;
	   		if($c2id)
	   		{
	   		    $where['where']  .= " and c2id = :c2id ";
	   			$where['bind']['c2id']= $c2id;
	   			if($c3id)
		   		{
		   		    $where['where']  .= " and c3id = :c3id ";
		   			$where['bind']['c3id']= $c3id;
		   			if($c4id)
			   		{
			   		    $where['where']  .= " and c4id = :c4id ";
			   			$where['bind']['c4id']= $c4id;
			   		}
		   		}
	   		}
       }
       if($gLocation)
	   {
			if(is_numeric($gLocation))
			{
			    $where['where'] 		.= "  and `gLocation` = 0 ";
			}
			$where['where'] 		.= "  and `gLocationExt` = :gLocationExt ";
			$where['bind']['gLocationExt']= $gLocation;
	   }
       if($q)
	   {
			$where['where'] 		.= "  and `sTitle` LIKE :sTitle ";
			$where['bind']['sTitle']= "%{$q}%";
	   }	   
	   if(empty($order) || $order == 'desc')
	   {
	       $order = ' order by dwValidDurationExt desc ';
	   }elseif($order == 'asc')
	   {
	       $order = ' order by dwValidDurationExt asc ';
	   }elseif($order == 'desc_p')
	   {
	  	   $order = ' order by dwPrice_bin desc ';
	   }elseif($order == 'asc_p')
	   {
	       $order = ' order by dwPrice_bin asc ';
	   }else
	   {
	       $order = "";
	   }
	   $table 		= $good?"shop_recommend_goods":"goods_info";	   
	   $pg			= pg::sp($db,$table,$where,$page,$rows);
	   
	   $rs 		    = $db->dataArray("select * from {$table} {$where['where']} {$order} limit {$pg['begin']},".$rows,$where['bind']);
	   
	   //echo $db->getsql();
	   //print_r($rs);
	   return array("pg"=>$pg,"rs"=>$rs);
    }
    static public function url_pct($q,$area=null,$urs=null)
    {
        return surl::en(surl::get("search")."index.php",array("q"=>$q,"area"=>$area,"urs"=>$urs));
    }
}
?>